package com.wayhome.order.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

@Configuration
public class ApplicationConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        //设置读取超时时间
        Duration readTimeOut = Duration.ofMillis(5);
        Duration connectTimeout = Duration.ofMillis(5);
        //设置连接超时时间
        builder.setReadTimeout(readTimeOut);
        builder.setConnectTimeout(connectTimeout);
        return builder.build();
    }
}
